package com.xiaoxin_project.Controller;

import com.xiaoxin_project.Util.IMoocJSONResult;
import com.xiaoxin_project.Util.MD5Utils;
import com.xiaoxin_project.pojo.Users;
import com.xiaoxin_project.pojo.vo.UsersVo;
import com.xiaoxin_project.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/a")
public class HelloController {
    @Autowired
    private UserService userService;
    @GetMapping("/hello")
    public String hello(@RequestBody Users user) throws Exception {
        //注册
        user.setNickName(user.getUserName());
        user.setFaceImage(null);
        user.setFaceImageBig(null);
        user.setPassWord(MD5Utils.getMD5Str(user.getPassWord()));
        //System.out.println(user.getCids());
        Users userResult = userService.saveUser(user);
        UsersVo userVo = new UsersVo();
        BeanUtils.copyProperties(userResult,userVo);
        return "注册成功";
    }

    @GetMapping("/hello2")
    public boolean hello2(@RequestBody Users user) throws Exception {
        boolean exist = userService.queryUsernameIsExist(user.getUserName());
        if(exist){
            return true;
        }
        else return false;
    }
}
